﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Live;
using Microsoft.Live.Controls;
using Common.Library;

namespace SyncStories
{
    public partial class SkyDriveLogin : PhoneApplicationPage
    {
        private LiveConnectClient client = null;
        private LiveConnectSession session = null;
        public SkyDriveLogin()
        {
            InitializeComponent();

            Loaded += SkyDriveLogin_Loaded;
        }

        void SkyDriveLogin_Loaded(object sender, RoutedEventArgs e)
        {
            btnSignIn.ClientId = "00000000480E7666";
            btnSignIn.Scopes = "wl.basic wl.signin wl.offline_access wl.skydrive_update";
            btnSignIn.Branding = BrandingType.Skydrive;
            btnSignIn.TextType = ButtonTextType.SignIn;
            btnSignIn.SessionChanged += btnSignIn_SessionChanged;
        }

        private void btnSignIn_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
        {
            // If the user is signed in.
            if (e.Status == LiveConnectSessionStatus.Connected)
            {
                session = e.Session;
                client = new LiveConnectClient(e.Session);
                AppSettings.SkyDriveLogin = true;
                
            }
            else  // Otherwise the user isn't signed in.
            {
                AppSettings.SkyDriveLogin = false;
            }
        }

       
    }
}